{extend name="public/header" /}
{block name="body"}
<body>
{include file="public/common" /}
<!--头部搜索开始-->
<div class="layui-collapse" lay-accordion="">
	<div class="layui-colla-item">
		<h2 class="layui-colla-title">搜索</h2>
		<div class="layui-colla-content layui-show">
			<form class="layui-form" action="{:url('admin/index')}">
				<div class="layui-form">
					<div class="layui-inline">
						<div class="layui-input-inline">
							<input class="layui-input" name="id" value="{$pageMaps.id|default=''}" placeholder="ID">
						</div>
					</div>
					<div class="layui-inline">
						<div class="layui-input-inline">
							<input class="layui-input" name="username" value="{$pageMaps.username|default=''}" placeholder="账号">
						</div>
					</div>
					<div class="layui-inline">
						<select name="status">
							<option value="">状态</option>
							<option value="1" {if condition="$pageMaps.status eq 1"} selected{/if}>正常</option>
							<option value="2" {if condition="$pageMaps.status eq 2"} selected{/if}>禁用</option>
						</select>
					</div>
					
					<div class="layui-inline">
						<button lay-submit class="layui-btn" lay-filter="search"><i class="layui-icon">&#xe615;</i>查找</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
<!--头部搜索结束-->
<div class="layui-form">
    <table class="layui-table" lay-size="sm">
        <thead>
        <tr>
            <th width="80">ID</th>
			<th>账号</th>
			<th>昵称</th>
			<th>组</th>
			<th>注册时间</th>
			<th>登录时间</th>
			<th>状态</th>
            <th width="160">操作</th>
        </tr>
        </thead>
        <tbody>
		{if(count($list)<1)}
            <tr>
                <td colspan="6" align="center">暂无相关数据</td>
            </tr>
            {else /}
			{volist name='list' id='vo' key='k'}
			<tr>
				<td>{$vo.id}</td>
				<td>{$vo.username}</td>
				<td>{$vo.nickname}</td>
				<td>{$vo.role_name}</td>
				<td>{:rttime($vo['addtime'])}</td>
				<td>{:rttime($vo['sorttime'])}</td>
				<td><input type="checkbox" lay-skin="switch" lay-filter="switch" value="{$vo.status}" lay-text="正常|禁用" {if $vo.status==1}checked{/if} data-url='{:url("ajax/upField",array("table"=>"admin","id_name"=>"id","id_value"=>$vo["id"],"field"=>"status"))}'></td>
				<td>
					<a class="layui-btn layui-btn-xs modal-catch" href="{:url('admin/info',array('id'=>$vo['id']))}">
						<i class="layui-icon">&#xe642;</i>编辑
					</a>
					<a class="layui-btn layui-btn-xs layui-btn-danger ajax-del" data-url='{:url("admin/del")}' data-field='id' data-value='{$vo.id}'>
						<i class="layui-icon">&#xe640;</i>删除
					</a>
					<a class="layui-btn layui-btn-xs layui-btn-danger ajax-edit" data-modal="{:url('admin/password',array('id'=>$vo.id))}">密</a>
				</td>
			</tr>
			{/volist}
		{/if}
        </tbody>
    </table>
</div>
<div class="text-right">
    <div class="layui-box layui-laypage layui-laypage-molv" id="layui-laypage">
		{$_page|raw}
    </div>
</div>
</body>
{/block}
{block name="script"}
<script>
layui.use(['jquery','laydate','form','layajax','layer'], function(){
	var $ = layui.jquery
		,form = layui.form
		,laydate = layui.laydate
		,layer = layui.layer
		,layajax = layui.layajax;

	$('.ajax-edit').on('click',function(){
		var url = $(this).attr('data-modal');
		var title = $(this).html();
		layer.open({
			type: 2,
			title: title,
			shadeClose: true,
			maxmin: false, //开启最大化最小化按钮
			shadeClose: false,
			area: ['400px', '400px'],
			content: url,
			btn: ['确定', '取消'],
			yes: function (index, layero) {
				var n = $(layero).find('iframe')[0];

				var obja = $(n).contents().find("input[name='id']");
				var objb = $(n).contents().find("input[name='password']");
				var objc = $(n).contents().find("input[name='twopassword']");
				var objd = $(n).contents().find("input[name='token']");
				var id = $(obja).val();
				var password = $(objb).val();
				var twopassword = $(objc).val();
				var token = $(objd).val();

				//reg = /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)])+$).{6,}$/;	//密码长度8-16位 必须由大写字母，小写字母，数字，特殊符号组成
				reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/;	//密码必须由6-12位数字加字母组成
				if(password=='' || password==0 || !reg.test(password)){
					layer.msg('请输入6-16位包含字母和数字的密码');
					return false;
				}
				if(twopassword==''){
					layer.msg('请输入确认密码');
					return false;
				}
				if(password!=twopassword){
					layer.msg('两次密码输入不一致');
					return false;
				}
				if(token==''){
					layer.msg('请输入口令');
					return false;
				}

				$.post('{:url("admin/password")}', {'id': id, 'password': password, 'twopassword': twopassword, 'token': token}, function (res) {
					if(res.code==undefined){
						console.log('res为json字符串',res);
						res = JSON.parse(res);
					}else{
						console.log('res为json对象',res);
					}
					if(res.code == 1) {
						layer.close(index);
						layer.msg(res.msg,{icon:1,time:2000}, function(index){
							location.reload();
						});
					} else {
						layer.close(index);
						layer.msg(res.msg);
					}
				});
			},
			btn2: function (index, layero) {
				layer.close(index);
			},
			cancel: function () {
				//右上角关闭回调
				return true //开启该代码可禁止点击该按钮关闭
			}
		});
	});

	form.render();
});
</script>
{/block}